/**
 * 设置灰度模式
 */
export const toggleGrayMode = (status) => {
  if (status) {
    document.body.className = document.body.className + ' grayMode'
  } else {
    document.body.className = document.body.className.replace(' grayMode', '')
  }
}
/**
 * 设置主题
 */
export const setTheme = (name) => {
  ['theme-default', 'theme-2k'].map(function (item) {
    document.body.classList.remove(item)
  })
  document.body.classList.add(name)
}

export const bin_to_hex = (str) => {
  let hex_array = [{
      key: 0,
      val: "0000"
    }, {
      key: 1,
      val: "0001"
    }, {
      key: 2,
      val: "0010"
    }, {
      key: 3,
      val: "0011"
    }, {
      key: 4,
      val: "0100"
    }, {
      key: 5,
      val: "0101"
    }, {
      key: 6,
      val: "0110"
    }, {
      key: 7,
      val: "0111"
    },
    {
      key: 8,
      val: "1000"
    }, {
      key: 9,
      val: "1001"
    }, {
      key: 'a',
      val: "1010"
    }, {
      key: 'b',
      val: "1011"
    }, {
      key: 'c',
      val: "1100"
    }, {
      key: 'd',
      val: "1101"
    }, {
      key: 'e',
      val: "1110"
    }, {
      key: 'f',
      val: "1111"
    }
  ]
  let value = ''
  let list = []
  if (str.length % 4 !== 0) {
    let a = "0000"
    let b = a.substring(0, 4 - str.length % 4)
    str = b.concat(str)
  }
  while (str.length > 4) {
    list.push(str.substring(0, 4))
    str = str.substring(4);
  }
  list.push(str)
  for (let i = 0; i < list.length; i++) {
    for (let j = 0; j < hex_array.length; j++) {
      if (list[i] == hex_array[j].val) {
        value = value.concat(hex_array[j].key)
        break
      }
    }
  }
  return value
}
